package com.genewu.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: jian
 * Date: Apr 5, 2010
 * Time: 1:27:24 AM
 * To change this template use File | Settings | File Templates.
 */
public class PropertiesUtil {

    private PropertiesUtil() {

    }

    /**
     * Load a properties file from the classpath
     *
     * @param name
     * @return Properties
     * @throws Exception
     */
    public static Properties loadPropertiesClasspath(String name) {
        Properties properties = new Properties();
        URL url = ClassLoader.getSystemResource(name);
        try {
            properties.load(url.openStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    /**
     * Load a Properties File
     *
     * @param file
     * @return Properties
     * @throws IOException
     * @deprecated
     */
    private static Properties loadPropertiesByFile(File file) throws IOException {
        Properties props = new Properties();
        FileInputStream fis = new FileInputStream(file);
        props.load(fis);
        fis.close();
        return props;
    }
}
